<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/fragments/head">
<title>角色编辑</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<div th:replace="admin/fragments/header"></div>
		<div th:replace="admin/fragments/mainsidebar::mainside('角色编辑','role')"></div>

		<div class="content-wrapper">
			<section class="content-header">
				<h1>角色编辑</h1>
			</section>

			<section class="content">
				<div class="row">
					<div class="col-md-12">
						<div class="box  box-primary">
							<div class="box-body">
								<ul id="tree" class="ztree"></ul>
							</div>
							<div class="box-footer">
								<button type="button" class="btn btn-default btn-back">返回</button>
								<button type="button" class="btn btn-info pull-right btn-submit">提交</button>
							</div>
						</div>
					</div>
				</div>
			</section>
		</div>

		<div th:replace="admin/fragments/footer"></div>
	</div>

	<div th:replace="admin/fragments/script"></div>
	<script th:inline="javascript">
	/*<![CDATA[*/
	 var setting = {
		        check : {
		            enable : true
		        },
		        data : {
		            simpleData : {
		                enable : true
		            }
		        }
		    };
		    setting.check.chkboxType = {
		        "Y" : "ps",
		        "N" : "s"
		    };
		    $.ajax({
		        type : "POST",
		        url : "/admin/resource/tree/" + [[${role.id}]],
		        dataType : 'json',
		        success : function(msg) {
		            $.fn.zTree.init($("#tree"), setting, msg);
		        }
		    });


		    $(".btn-submit").click(function () {
		        var treeObj = $.fn.zTree.getZTreeObj("tree");
		        var nodes = treeObj.getCheckedNodes(true);
		        var selectIds="";
		        for(var index in nodes){
		            var item=nodes[index];
		            selectIds+=item.id+",";
		        }
		        $.ajax({
		            url : "/admin/role/grant/"+[[${role.id}]]+"?t=" + Math.random(),
		            type : "post",
		            dataType : "json",
		            data : {"resourceIds":selectIds},
		            success : function(msg) {
		                layer.msg(msg.message, {time: 2000},function(){
		                	
		                });
		            },
		            error : function(r,s,m) {
		            }
		        });
		    });
		    /*]]>*/
	</script>
</body>
</html>